from .events import *

class QToolsPanel(QToolsPanelFuncs):

    class DropBtnUIpy(wx.FileDropTarget):

        def __init__(self, mainFrameGUI):
            wx.FileDropTarget.__init__(self)
            self.mainFrameGUI = mainFrameGUI

        def OnDropFiles(self, x, y, filePath):
            '''拖拽释放后触发，(x, y) 表示坐标'''
            if wx.Shell("pyuic5 --version"):
                project_dir = filePath[0]
                self.mainFrameGUI.order_data.append(project_dir)
                if not self.mainFrameGUI.isChoiceUI:
                    self.mainFrameGUI.ui_py_btn_info += f'【{project_dir}】'
                    self.mainFrameGUI.btnChoiceUIandPath.SetLabel(BTN_CHOICE_UI_PY_PATH)
                    self.mainFrameGUI.isChoiceUI = True
                    self.mainFrameGUI.scollPanel.Refresh()
                    return True
                else:
                    return False
            else:
                RichMsgDialog.showOkMsgDialog(self.mainFrameGUI, '请先安装QT for Python。', '错误')
                return False
            

    def __init__( self, parent=None):
        super().__init__(parent=parent)

        self._init_drag()


    def _init_drag(self):
        """初始化拖拽对象"""
        self.dropBtnUIpy = QToolsPanel.DropBtnUIpy(self)
        self.btnChoiceUIandPath.SetDropTarget(self.dropBtnUIpy)

    def __del__(self):
        """释放资源"""
        try:
            status = wx.Kill(self.pid_pyside6_designer)
            # print(status)
        except: ...
